package com.haircut.sys.controller.user;

import cn.hutool.core.util.StrUtil;
import com.haircut.sys.service.user.IUserService;
import com.haircut.sys.vo.DataSttsVo;
import com.haircut.sys.vo.user.*;
import com.modular.constant.BaseCodeDesc;
import com.modular.exception.ModularException;
import com.modular.result.PageResult;
import com.modular.result.RspMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户管理")
@RestController
@RequestMapping("/b/user")
public class UserController {
    @Autowired
    private IUserService userService;

    /**
     * 新增用户
     * @param userVo
     * @return
     */
    @ApiOperation(value = "新增用户")
    @PostMapping("saveUser")
    public RspMessage<Void> saveUser(@Validated @RequestBody  UserAddVo userVo){
        userService.save(userVo);
        return RspMessage.success();
    }

    /**
     * 修改用户
     * @param userVo
     * @return
     */
    @ApiOperation(value = "修改用户")
    @PostMapping("modifyUser")
    public RspMessage<Void> modifyUser(@Validated @RequestBody  UserVo userVo){
        if(StrUtil.isBlank(userVo.getId())){
            throw new ModularException(BaseCodeDesc.DEFATUL_MSG,"用户id错误");
        }
        userService.update(userVo);
        return RspMessage.success();
    }

    /**
     * 修改用户
     * @param userVo
     * @return
     */
    @ApiOperation(value = "修改当前登录人用户")
    @PostMapping("modifyProfile")
    public RspMessage<Void> modifyProfile(@Validated @RequestBody  UserOnlyVo userVo){
        userService.modifyProfile(userVo);
        return RspMessage.success();
    }
    /**
     * 修改用户
     * @param userVo
     * @return
     */
    @ApiOperation(value = "修改当前登录人用户")
    @PostMapping("updatePwd")
    public RspMessage<Void> updatePwd(@Validated @RequestBody  UpdatePwdVo userVo){
        userService.updatePwd(userVo);
        return RspMessage.success();
    }


    /**
     * 重置密码
     * @param userVo
     * @return
     */
    @ApiOperation(value = "重置密码")
    @PostMapping("resetPwd")
    public RspMessage<Void> resetPwd(@RequestBody UserPwdVo userVo){
        userService.resetPwd(userVo);
        return RspMessage.success();
    }

    /**
     * 修改用户状态
     * @param dataSttsVo
     * @return
     */
    @ApiOperation(value = "修改用户状态")
    @PostMapping("modifyDataStts")
    public RspMessage<Void> modifyDataStts(@RequestBody DataSttsVo dataSttsVo){
        userService.modifyDataStts(dataSttsVo);
        return RspMessage.success();
    }


    /**
     * 修改用户状态
     * @param userId
     * @return
     */
    @ApiOperation(value = "修改用户状态")
    @GetMapping("findDetail")
    public RspMessage<UserVo> findDetail(@ApiParam("用户id") @RequestParam("userId") String userId){
        return RspMessage.success(userService.findDetail(userId));
    }

    /**
     * 修改用户状态
     * @param reqVo
     * @return
     */
    @ApiOperation(value = "分页查询用户信息")
    @PostMapping("findPage")
    public RspMessage<PageResult<UserResVo>> findPage(@RequestBody UserReqVo reqVo){
        return RspMessage.success(userService.findPage(reqVo));
    }


}
